package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import mx.core.Container;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.MarketingApplicationFacade;
	import vn.demand.dragon.view.QuotationNewFormMediator;
	
	public class CloseNewQuotationPanelCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			RIALogger.debug(this, "CloseNewQuotationPanelCommand::execute");
			var quotationVO:Object = note.getBody();
			var formId:String = QuotationNewFormMediator.makeId(quotationVO);
			var m:QuotationNewFormMediator = facade.retrieveMediator(formId) as QuotationNewFormMediator;
			var tab:Container = m.quotationForm as Container;
			if (tab == null) return;
			facade.removeMediator(formId);
			facade.removeProxy(formId);
			TabManager.removeTab(tab);
			if (note.getType() != null && note.getType() == "nosave") {
				return;
			}
			quotationVO.quote_code = quotationVO.real_code;
			sendNotification(MarketingApplicationFacade.QUOTATION_SELECTED, quotationVO);
        }
	}
}